/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024.
 * Description: rtos security internal common function
 * Author: xiongshenglan
 * Create: 2024-03-29
 */

#ifndef RTOS_SEC_INTERNAL_H
#define RTOS_SEC_INTERNAL_H

#include <crypto/hash.h>

#ifdef CONFIG_CRYPTO_HASH2
static inline int rtos_calc_sha256(const u8 *data, unsigned int len, u8 *out)
{
	const char *algo = "sha256";
	struct crypto_shash *tfm;
	int ret;

	if (!data || !out || len == 0)
		return -EINVAL;

	tfm = crypto_alloc_shash(algo, 0, 0);
	if (IS_ERR(tfm)) {
		pr_err("%s: can't alloc alg %s\n", __func__, algo);
		return PTR_ERR(tfm);
	}

	ret = crypto_shash_tfm_digest(tfm, data, len, out);
	crypto_free_shash(tfm);
	return ret;
}
#else
static inline int rtos_calc_sha256(const u8 *data, unsigned int len, u8 *out)
{
	return -1;
}
#endif
#endif
